package com.mobile.config;



import cn.hutool.core.thread.ThreadFactoryBuilder;
import org.apache.tomcat.util.threads.ThreadPoolExecutor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

@Configuration
public class EmbeddingConfig {

    /**
     * 创建一个线程池，用于处理向量数据库的初始化任务
     * @return 线程池
     */
    @Bean("embeddingExecutor")
    public ExecutorService embeddingExecutor() {
        return new ThreadPoolExecutor(
                2,  // 核心线程数
                4,  // 最大线程数
                60L, TimeUnit.SECONDS,  // 空闲线程存活时间
                new LinkedBlockingQueue<>(100),  // 任务队列
                new ThreadFactoryBuilder()
                        .setNamePrefix("embedding-pool-%d")
                        .setDaemon(false)
                        .build(),
                new ThreadPoolExecutor.CallerRunsPolicy() // 拒绝策略
        );
    }
}
